package com.example.testrecorder.utils;

import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.Toast;

import com.example.testrecorder.EditIssueActivity;

/**
 * @author Yingyong Lao
 * 创建时间 2021/5/30 19:56
 * @version 1.0
 */
public class MyTextWatcher implements TextWatcher {
    private EditText editText;
    private int maxLen;//编辑框中内容的最大长度
    private Activity activity;
    private CharSequence content;//编辑框中的内容

    public MyTextWatcher(EditText editText,Activity activity){//构造器
        this.activity=activity;
        this.editText=editText;
        maxLen= ViewUtil.getMaxLength(editText);//通过反射获取编辑框内容的最大长度
    };

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        content=s;
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if(TextUtils.isEmpty(content)){
            return;
        }
        if(content.length()==20){
            ViewUtil.hideAllInputMethod(activity);//隐藏输入法
            Toast.makeText(activity,"标题最多20个字符",Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void afterTextChanged(Editable s) {

    }
}
